<template>
    <div class="app-container">
        <el-card>
            <el-row slot="header">密码修改</el-row>
            <el-form ref="formRef" :model="formModel" style="width: 30%;">
                <el-form-item label="原有密码" prop="orgPassword" required>
                    <el-input v-model="formModel.orgPassword"></el-input>
                </el-form-item>
                <el-form-item label="新密码" prop="password" required>
                    <el-input v-model="formModel.password" type="password"></el-input>
                </el-form-item>
                <el-form-item label="确认新密码" prop="rePassword" required>
                    <el-input v-model="formModel.rePassword" type="password"></el-input>
                </el-form-item>
            </el-form>
            <el-row type="flex">
                <el-button style="width: 200px" @click="savePassword" type="primary" size="small"
                    >保存</el-button
                >
            </el-row>
        </el-card>
    </div>
</template>

<script>
import { updatePassword } from '@/api/login';

export default {
    data() {
        return {
            formModel: {
                orgPassword: '',
                password: '',
                rePassword: ''
            }
        };
    },
    methods: {
        savePassword() {
            this.$refs.formRef.validate(valid => {
                if (valid) {
                    updatePassword(this.formModel)
                        .then(res => {
                            if (res.data.success) {
                                this.$message({
                                    message: '修改密码成功!',
                                    type: 'info',
                                    duration: 3000
                                });
                            } else {
                                this.$message({
                                    message: res.data.msg,
                                    type: 'error',
                                    duration: 3000
                                });
                            }
                        })
                        .catch(err => {});
                } else {
                    this.$refs.formRef.resetFields();
                }
            });
        }
    }
};
</script>
<style lang="scss" scoped></style>
